<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>编辑工作流</title>
<jsp:include page="../../pages/head.jsp" />
<link rel="stylesheet" type="text/css" media="screen" href="<%=path %>/js/jquery.combogrid/resources/css/smoothness/jquery-ui-1.10.1.custom.css"/>
<script type="text/javascript" src="<%=path %>/js/jquery.combogrid/resources/jquery/jquery-ui-1.10.1.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="<%=path %>/js/dropdown-check-list/src/ui.dropdownchecklist.themeroller.css" />
<script type="text/javascript" src="<%=path %>/js/dropdown-check-list/src/ui.dropdownchecklist.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="<%=path %>/js/jquery.combogrid/resources/css/smoothness/jquery.ui.combogrid.css"/>
<script type="text/javascript" src="<%=path %>/js/jquery.combogrid/resources/plugin/jquery.ui.combogrid-1.6.3.js"></script>
<script type="text/javascript">

	function save(){
		if (!checkForm(document.getElementById("saveForm"))) {
			return;
		}
		xbox.load("loading");	
		$("#saveForm").ajaxSubmit(function(data){
			xbox.ready("loading");
			if(data==1){
				xbox.alert("选中的角色名称已经存在工作流信息，不允许重新添加同一角色信息！");
				return;
			}
	    	$("#refreshForm").submit();
	    });
	}
	function roleChange(obj){
		var roleNames = "";
		$(obj).children().each(function(){
			if($(this).attr("selected")){
				roleNames+=( roleNames=="" ? "":",") + $(this).html(); 
			}
		});
		$("#auditRoleNames").val(roleNames);
	}
	function turnBack(){
		xbox.load("loading");
	   $("#refreshForm").submit();
	}
	$(function(){
		$("#workFlowClass").val("${workFlow.workFlowClass}");
		$("#roleId").val("${workFlow.role.roleId}");
		if('${workFlow.isEnd}'=='1')
			$("#isEndYes").attr("checked",true);
		var ids = "${workFlow.auditRoleIds}";
		var array = ids.split(",");
		for(var i=0;i<array.length;i++){
			$("#auditRoleIds>[value='"+$.trim(array[i])+"']:first").prop("selected",true);
		}
		$("#auditRoleIds").dropdownchecklist( { emptyText: "请选择角色", maxDropHeight: 150, width: 240 } );
	});

</script>

</head>
<body>
<form action="<%=path%>/workflow/workflowAjax_modify_resultAction.action" method="post" id="saveForm">
<input type="hidden" name="workFlow.workFlowId" value="${workFlow.workFlowId}"/>
<table width="98%" align="center" border="0" cellpadding="4" cellspacing="0" bgcolor="#F1F1F1" >
  <tr bgcolor="#FFFFFF">
    <td colspan="4" height="16"><span></span></td>
  </tr>
  <tr bgcolor="#FFFFFF">
    <td width="10%" align="right" bgcolor="#FFFFFF"><span style="color:red;">*</span>所属模块：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
         <select id="workFlowClass" name="workFlow.workFlowClass">
   				<option value="需求申请">需求申请</option>
   		</select>
    </td>
    <td width="10%" align="right" bgcolor="#FFFFFF">角色名称：</td>
    <td width="40%" align="left" bgcolor="#FFFFFF">
          <select id="roleId" name="workFlow.role.roleId" isNull="角色名称">
   			<c:forEach items="${roleList}" var="role">
   				<option value="${role.roleId}">${role.roleName}</option>
   			</c:forEach>
   		</select>
    </td>
  </tr>
   <tr bgcolor="#FFFFFF">
    <td align="right" bgcolor="#FFFFFF">被审角色：</td>
    <td align="left" bgcolor="#FFFFFF">
         <select id="auditRoleIds" name="workFlow.auditRoleIds" isNull="被审角色" class="roleIds" multiple="multiple" onchange="roleChange(this)">
   			<c:forEach items="${roleList}" var="role">
   				<option value="${role.roleId}">${role.roleName}</option>
   			</c:forEach>
   		</select>
   		<input type="hidden" id="auditRoleNames" value="${workFlow.auditRoleNames}" name="workFlow.auditRoleNames"/>
    </td>
    <td align="right" bgcolor="#FFFFFF">是否终审：</td>
    <td align="left" bgcolor="#FFFFFF">
    	<table cellpadding="0" cellspacing="0" border="0">
    		<tr>
    		<td><input type="radio" name="workFlow.isEnd" id="isEndYes" value="1"/></td><td style="padding-right: 20px;"><label for="isEndYes">是</label></td>
    		<td><input type="radio" name="workFlow.isEnd" id="isEndNo" value="0"  checked="true"/></td><td><label for="isEndNo">否</label></td>
    		</tr>
    	</table>
    </td>
  </tr>
  <tr align="right" bgcolor="#F1F1F1">
	<td height="36" colspan="4" align="center">
		<input type='button' class="btn btn-primary" id="btnSave" onclick="save();" value='保存' />
	    <input type='button' class="btn" onclick="turnBack();" value='返回' />
</td>
</tr>
</table>
</form>

<form action="${listUrl}" method="post" style="display: none;" id="refreshForm" name="refreshForm"/>
	

</body>
</html>
